package com.lmx.repoDomain.tmodel;


import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import com.lmx.repoDomain.tmodel.business.User;

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToMany;
import io.katharsis.resource.annotations.JsonApiToOne;


/**
 * 护理组表
 */
@JsonApiResource(type = "nursegroup")
@Table(name = "tnb_NurseGroup")
@Entity
public class NurseGroup extends BaseEntity {

	private String remark;// 备注

	private String name;

	private User lastUpdateUser;// 更新操作者userid

	private Integer createDateTime;// 创建时间

	private User createUser;

	private Integer lastUpdateDateTime;// 更新时间

	private Employee leader;// 组长

	private List<EmployeeNursingGroup> staffs;// 所包含护工

	private List<BedNurseGroup> beds;// 所护理房间
	
	private List<Customer> customers;

	@Transient
	@JsonApiToMany
	@JsonApiIncludeByDefault 
	public List<Customer> getCustomers() {
		return customers;
	}

	public void setCustomers(List<Customer> customers) {
		this.customers = customers;
	}

	@JsonApiToMany
	//@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "nurseGroup")
	@JsonApiIncludeByDefault
	@Fetch(FetchMode.JOIN)
	@ManyToMany(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
	@JoinTable(name = "tnb_employee_nursingGroup", joinColumns = {
			@JoinColumn(name = "group_id", nullable = false, updatable = false, foreignKey = @ForeignKey(name = "null")) }, inverseJoinColumns = {
					@JoinColumn(name = "employee_id", nullable = false, updatable = false, foreignKey = @ForeignKey(name = "null")) })
	public List<EmployeeNursingGroup> getStaffs() {
		return staffs;
	}

	public void setStaffs(List<EmployeeNursingGroup> staffs) {
		this.staffs = staffs;
	}
	//@JsonApiIncludeByDefault
	@JsonApiToMany
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "tnb_bed_nursegroup", joinColumns = {
			@JoinColumn(name = "group_id", nullable = false, updatable = false, foreignKey = @ForeignKey(name = "null")) }, inverseJoinColumns = {
					@JoinColumn(name = "bed_id", nullable = false, updatable = false, foreignKey = @ForeignKey(name = "null")) })
	public List<BedNurseGroup> getBeds() {
		return beds;
	}

	public void setBeds(List<BedNurseGroup> beds) {
		this.beds = beds;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "leader_id", foreignKey = @ForeignKey(name = "null"))
	public Employee getLeader() {
		return leader;
	}

	public void setLeader(Employee leader) {
		this.leader = leader;
	} 

	@Column(name = "createDateTime")
	public Integer getCreateDateTime() {
		return createDateTime;
	} 

	public void setCreateDateTime(Integer createDateTime) {
		this.createDateTime = createDateTime;
	}

	@Column(name = "lastUpdateDateTime")
	public Integer getLastUpdateDateTime() {
		return lastUpdateDateTime;
	}

	public void setLastUpdateDateTime(Integer lastUpdateDateTime) {
		this.lastUpdateDateTime = lastUpdateDateTime;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "createuser_id", foreignKey = @ForeignKey(name = "null"))
	public User getCreateUser() {
		return createUser;
	}

	public void setCreateUser(User createUser) {
		this.createUser = createUser;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "lastupdateuser_id", foreignKey = @ForeignKey(name = "null"))
	public User getLastUpdateUser() {
		return lastUpdateUser;
	}

	public void setLastUpdateUser(User lastUpdateUser) {
		this.lastUpdateUser = lastUpdateUser;
	}

	@Column(name = "name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public NurseGroup() {
	}

	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

}
